/*
 *
 *  Connection Manager
 *
 *  Copyright (C) 2007-2009  Intel Corporation. All rights reserved.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License version 2 as
 *  published by the Free Software Foundation.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */

#include <glib.h>

#define CONNMAN_API_SUBJECT_TO_CHANGE

#include <connman/dbus.h>

#define NM_SERVICE    "org.freedesktop.NetworkManager"
#define NM_PATH       "/org/freedesktop/NetworkManager"
#define NM_INTERFACE  NM_SERVICE

int __connman_dbus_init(DBusConnection *conn);
void __connman_dbus_cleanup(void);

DBusMessage *__connman_error_failed(DBusMessage *msg, int errnum);
DBusMessage *__connman_error_invalid_arguments(DBusMessage *msg);
DBusMessage *__connman_error_permission_denied(DBusMessage *msg);
DBusMessage *__connman_error_passphrase_required(DBusMessage *msg);
DBusMessage *__connman_error_not_registered(DBusMessage *msg);
DBusMessage *__connman_error_not_supported(DBusMessage *msg);
DBusMessage *__connman_error_not_implemented(DBusMessage *msg);
DBusMessage *__connman_error_not_found(DBusMessage *msg);
DBusMessage *__connman_error_no_carrier(DBusMessage *msg);
DBusMessage *__connman_error_in_progress(DBusMessage *msg);
DBusMessage *__connman_error_already_exists(DBusMessage *msg);
DBusMessage *__connman_error_already_enabled(DBusMessage *msg);
DBusMessage *__connman_error_already_disabled(DBusMessage *msg);
DBusMessage *__connman_error_already_connected(DBusMessage *msg);
DBusMessage *__connman_error_not_connected(DBusMessage *msg);
DBusMessage *__connman_error_operation_aborted(DBusMessage *msg);
DBusMessage *__connman_error_operation_timeout(DBusMessage *msg);
DBusMessage *__connman_error_invalid_service(DBusMessage *msg);
DBusMessage *__connman_error_invalid_property(DBusMessage *msg);
DBusMessage *__connman_error_invalid_ipconfig(DBusMessage *msg);
DBusMessage *__connman_error_invalid_debug_tag(DBusMessage *msg);
DBusMessage *__connman_error_invalid_passphrase(DBusMessage *msg);
DBusMessage *__connman_error_invalid_network_name(DBusMessage *msg);
DBusMessage *__connman_error_not_on_home_network(DBusMessage *msg);
DBusMessage *__connman_error_internal_error(DBusMessage *msg);

#include <connman/types.h>

int __connman_manager_init(gboolean compat);
void __connman_manager_cleanup(void);

int __connman_metrics_init(void);
void __connman_metrics_cleanup(void);
void __connman_metrics_state_changed(const char *state_name);

int __connman_agent_init(void);
void __connman_agent_cleanup(void);

int __connman_agent_register(const char *sender, const char *path);
int __connman_agent_unregister(const char *sender, const char *path);

struct connman_service;
typedef void (*connman_agent_cb_t)(struct connman_service *service,
				void *user_data, DBusMessageIter *dict);
int __connman_agent_request_input(struct connman_service *service,
				const char *params[],
				connman_agent_cb_t callback, void *user_data);

#include <connman/log.h>

int __connman_log_init(gboolean detach, unsigned debugmask);
void __connman_log_cleanup(void);

unsigned __connman_debug_getmask(void);
const gchar *__connman_debug_getmask_str(void);
unsigned __connman_debug_setmask(unsigned debugmask);
unsigned __connman_debug_tags_to_mask(const char *tags, GError **error);
gboolean __connman_debug_set_tags(char *taglist);


#include <connman/option.h>

#include <connman/plugin.h>

int __connman_plugin_init(char **pattern, char **exclude);
void __connman_plugin_cleanup(void);

#include <connman/task.h>

int __connman_task_init(void);
void __connman_task_cleanup(void);

#include <connman/security.h>

int __connman_security_check_privilege(DBusMessage *message,
				enum connman_security_privilege privilege);
int __connman_security_init(void);

#include <connman/ipconfig.h>

int __connman_ipconfig_init(void);
void __connman_ipconfig_cleanup(void);

void __connman_ipconfig_foreach(void *tag,
	void (*function)(struct connman_ipconfig *, void *arg), void *arg);
void __connman_ipdevice_foreach(void (*function)(int index, void *), void *);

const char *__connman_ipconfig_get_method(const struct connman_ipconfig *);
unsigned short __connman_ipconfig_get_type(int index);
const char *__connman_ipconfig_get_ifname(int index);
unsigned int __connman_ipconfig_get_flags(int index);
const char *__connman_ipconfig_get_gateway(int index);
connman_bool_t __connman_ipconfig_parse_type(const char *,
	enum connman_ipconfig_type *);

struct connman_device;
void __connman_ipconfig_get_keys(struct connman_device *device,
    int maxnames, const char const *names[], int *count);

#include <connman/inet.h>

enum connman_device_type __connman_inet_get_device_type(int index);

int __connman_ipv4_init(void);
void __connman_ipv4_cleanup(void);

int __connman_ipv6_init(void);
void __connman_ipv6_cleanup(void);

#include <connman/wifi.h>

#include <connman/rfkill.h>

int __connman_rfkill_init(void);
void __connman_rfkill_cleanup(void);

#include <connman/resolver.h>

int __connman_resolver_init(void);
void __connman_resolver_cleanup(void);

int __connman_resolver_selftest(void);

#include <connman/crypto.h>

int __connman_crypto_init(void);
void __connman_crypto_cleanup(void);

char *__connman_crypto_encrypt_keyvalue(const char *key, const char *value);
char *__connman_crypto_decrypt_keyvalue(const char *key, const char *value);

#include <connman/storage.h>

int __connman_storage_init(void);
void __connman_storage_cleanup(void);

gboolean __connman_storage_exists(const struct connman_storage_ident *ident);
GKeyFile *__connman_storage_open(const struct connman_storage_ident *ident);
void __connman_storage_close(const struct connman_storage_ident *ident,
					GKeyFile *keyfile, gboolean save);
void __connman_storage_delete(const struct connman_storage_ident *ident);

void __connman_storage_set_encrypted_value(GKeyFile *keyfile,
    const char *section, const char *key, const char *value);
char *__connman_storage_get_encrypted_value(GKeyFile *keyfile,
    const char *section, const char *key);

int __connman_storage_init_profile(void);
int __connman_storage_load_profile(struct connman_profile *profile);
int __connman_storage_save_profile(struct connman_profile *profile);
int __connman_storage_load_service(struct connman_service *service,
    const struct connman_storage_ident *profile_ident);
int __connman_storage_save_service(struct connman_service *service,
    const struct connman_storage_ident *profile_ident);
char *__connman_storage_find_guid(const char *guid,
    const struct connman_storage_ident *profile_ident);
int __connman_storage_load_provider(struct connman_provider *provider,
    const struct connman_storage_ident *profile_ident);
int __connman_storage_save_provider(struct connman_provider *provider,
    const struct connman_storage_ident *profile_ident);
int __connman_storage_load_device(struct connman_device *device,
    const struct connman_storage_ident *profile_ident);
int __connman_storage_save_device(struct connman_device *device,
    const struct connman_storage_ident *profile_ident);
int __connman_storage_load_ipconfig(struct connman_ipconfig *ipconfig,
    const struct connman_storage_ident *profile_ident);
int __connman_storage_save_ipconfig(const struct connman_ipconfig *ipconfig,
    const struct connman_storage_ident *profile_ident);

#include <connman/driver.h>

void __connman_driver_rescan(struct connman_driver *driver);

#include <connman/element.h>

int __connman_element_init(char **devices, char **nodevices, const char *order);
void __connman_element_start(void);
void __connman_element_stop(void);
void __connman_element_cleanup(void);

void __connman_element_initialize(struct connman_element *element);

typedef void (* element_cb_t) (struct connman_element *element,
							gpointer user_data);

void __connman_element_foreach(struct connman_element *element,
				enum connman_element_type type,
				element_cb_t callback, gpointer user_data);
void __connman_element_list(struct connman_element *element,
					enum connman_element_type type,
							DBusMessageIter *iter);
int __connman_element_count(struct connman_element *element,
					enum connman_element_type type);

struct connman_service *__connman_element_get_service(struct connman_element *element);

struct connman_device *__connman_element_find_device(enum connman_device_type type);

#include <connman/service.h>
int __connman_element_request_scan(enum connman_service_type type);
int __connman_element_enable_technology(enum connman_service_type type);
int __connman_element_disable_technology(enum connman_service_type type);

const char *__connman_element_type2string(enum connman_element_type type);
enum connman_service_error __connman_element_convert_error(
		enum connman_element_error error);

static inline void __connman_element_lock(struct connman_element *element)
{
}

static inline void __connman_element_unlock(struct connman_element *element)
{
}

int __connman_element_append_ipv4(struct connman_element *element,
						DBusMessageIter *dict);
int __connman_element_set_ipv4(struct connman_element *element,
				const char *name, DBusMessageIter *value);

int __connman_ipv4_init(void);
void __connman_ipv4_cleanup(void);

int __connman_connection_init(void);
void __connman_connection_cleanup(void);

struct connman_element *__connman_connection_create(
	struct connman_ipconfig *ipconfig, struct connman_element *parent);
connman_bool_t __connman_connection_is_online(void);
void __connman_connection_resort(void);

int __connman_udev_init(void);
void __connman_udev_start(void);
void __connman_udev_cleanup(void);
char *__connman_udev_get_devtype(const char *ifname);
connman_bool_t __connman_udev_has_associated_modem(const char *ifname);
void __connman_udev_rfkill(const char *sysname, connman_bool_t blocked);

gboolean __connman_device_isfiltered(const char *devname);

#include <connman/device.h>

int __connman_device_init(void);
void __connman_device_cleanup(void);

enum connman_service_type __connman_device_get_service_type(struct connman_device *device);

int __connman_device_get_phyindex(struct connman_device *device);
void __connman_device_set_phyindex(struct connman_device *device,
							int phyindex);
int __connman_device_set_blocked(struct connman_device *device,
						connman_bool_t blocked);

struct connman_network *__connman_device_get_current_network(
	struct connman_device *device);
void __connman_device_set_current_network(struct connman_device *device,
					struct connman_network *network);
void __connman_device_set_reconnect(struct connman_device *device,
	connman_bool_t onoff);
connman_bool_t __connman_device_get_reconnect(struct connman_device *device);
void __connman_device_mark_networks_unavailable(struct connman_device *device);
void __connman_device_cleanup_networks(struct connman_device *device);

int __connman_device_enable(struct connman_device *device);
int __connman_device_enable_persistent(struct connman_device *device);
int __connman_device_disable(struct connman_device *device);
int __connman_device_disable_persistent(struct connman_device *device);
int __connman_device_connect(struct connman_device *device);
int __connman_device_disconnect(struct connman_device *device);

void __connman_device_remove_ipconfig(struct connman_device *device,
					struct connman_ipconfig *ipconfig);

connman_bool_t __connman_device_has_driver(struct connman_device *device);

const char *__connman_device_get_type(struct connman_device *device);
const char *__connman_device_get_ident(struct connman_device *device);

int __connman_device_set_offlinemode(connman_bool_t offlinemode);
connman_bool_t __connman_device_roaming_allowed(struct connman_device *device);

#include <connman/network.h>

int __connman_network_init(void);
void __connman_network_cleanup(void);

void __connman_network_set_device(struct connman_network *network,
					struct connman_device *device);

int __connman_network_connect(struct connman_network *network);
int __connman_network_disconnect(struct connman_network *network);

connman_bool_t __connman_network_has_driver(struct connman_network *network);

const char *__connman_network_get_type(struct connman_network *network);
const char *__connman_network_get_group(struct connman_network *network);
const char *__connman_network_get_ident(struct connman_network *network);
connman_bool_t __connman_network_get_weakness(struct connman_network *network);
connman_bool_t __connman_network_get_connecting(struct connman_network *network);

int __connman_network_activate_cellular_modem(struct connman_network *network,
                                              const char *carrier);

struct connman_network *__connman_network_find_other_network(
    struct connman_network *network);

int __connman_portal_init(void);
void __connman_portal_cleanup(void);
void __connman_portal_service_recheck_state(struct connman_service *service);

#include <connman/profile.h>

int __connman_profile_init();
int __connman_profile_push_batch(char **profiles);
void __connman_profile_cleanup(void);

connman_bool_t __connman_profile_get_offlinemode(void);
int __connman_profile_set_offlinemode(connman_bool_t offlinemode);
uint32_t __connman_profile_get_checkportal(void);
int __connman_profile_set_checkportal(uint32_t checkportal);
const char *__connman_profile_get_portal_url(void);
int __connman_profile_set_portal_url(const char *url);
int __connman_profile_save_default(void);

int __connman_profile_load_service(struct connman_service *service);
int __connman_profile_load_device_service(struct connman_service *service);
int __connman_profile_save_service(struct connman_service *service);
char *__connman_profile_find_guid(const char *);
int __connman_profile_load_provider(struct connman_provider *provider);
int __connman_profile_save_provider(struct connman_provider *provider);
int __connman_profile_load_device(struct connman_device *device);
int __connman_profile_save_device(struct connman_device *device);
int __connman_profile_load_ipconfig(struct connman_ipconfig *ipconfig);
int __connman_profile_save_ipconfig(const struct connman_ipconfig *ipconfig);

int __connman_profile_append_hidden_ssids(GSList **hidden_ssids,
    void (*append_hidden_ssids)(GKeyFile *keyfile, GSList **hidden_ssids));

void __connman_profile_list(DBusMessageIter *iter, void *);
const char *__connman_profile_get_path(const struct connman_profile *profile);
struct connman_profile *__connman_profile_lookup_profile(const char *path);
struct connman_profile *__connman_profile_active_profile(void);
const struct connman_storage_ident *__connman_profile_active_ident(void);
const char *__connman_profile_active_path(void);

int __connman_profile_create(const char *name, const char **path);
int __connman_profile_remove(const char *ident);
int __connman_profile_push(const char *ident, const char *name,
				const char **path);
int __connman_profile_pop(const char *ident);

int __connman_profile_delete_entry(struct connman_profile *profile,
    const char *group);

void __connman_profile_changed(struct connman_profile *, gboolean delayed);

int __connman_profile_add_device(struct connman_device *device);
int __connman_profile_remove_device(struct connman_device *device);

int __connman_profile_add_network(struct connman_network *network);
int __connman_profile_update_network(struct connman_network *network);
int __connman_profile_remove_network(struct connman_network *network);

#include <connman/provider.h>

struct __connman_provider_append_properties_args {
	DBusMessage *msg;
	struct connman_provider *provider;
};
void __connman_provider_append_properties(DBusMessageIter *iter, void *arg);

struct __connman_provider_append_profile_properties_args {
	GKeyFile *keyfile;
	const char *ident;
};
void __connman_provider_append_profile_properties(DBusMessageIter *dict,
    void *arg);

void __connman_provider_list(DBusMessageIter *iter, void *user_data);
DBusMessage *__connman_provider_create(DBusMessage *msg,
					struct connman_service **service_out,
					connman_bool_t *created_out);
DBusMessage *__connman_provider_create_by_identifier(DBusMessage *msg,
					const char *ident);
int __connman_provider_indicate_state(struct connman_provider *provider,
					enum connman_provider_state state);
int __connman_provider_indicate_error(struct connman_provider *provider,
					enum connman_provider_error error);
int __connman_provider_connect(struct connman_provider *provider);
int __connman_provider_disconnect(struct connman_provider *provider);
void __connman_provider_remove(struct connman_provider *provider);
struct connman_service *__connman_provider_get_service(struct connman_element *);
DBusMessage *__connman_provider_set_property(struct connman_provider *provider,
    DBusMessage *msg, const char *name, DBusMessageIter *value);

struct connman_profile *__connman_provider_get_profile(
    struct connman_provider *provider);
void __connman_provider_set_profile(struct connman_provider *provider,
    struct connman_profile *profile);

void __connman_provider_cleanup(void);
int __connman_provider_init(void);

#include <connman/service.h>

#define	MAX_WEP_KEYSPACE	13
#define WPA_PMK_KEYLENGTH	32
#define MAX_SSID_LENGTH		32

int __connman_service_init(const char *order);
void __connman_service_cleanup(void);

void __connman_service_list(DBusMessageIter *iter, void *);
void __connman_service_watchlist(DBusMessageIter *iter, void *);
const char *__connman_service_default(void);

void __connman_service_put(struct connman_service *service);

/* NB: returned string must be free'd */
char *__connman_service_get_ordering(void);
int __connman_service_set_ordering(const char *str);

struct connman_service *__connman_service_lookup_from_device(
					struct connman_device *device);
int __connman_service_create_from_device(struct connman_device *device);
void __connman_service_remove_from_device(struct connman_device *device);

int __connman_service_create_from_network(struct connman_network *network);
void __connman_service_update_strength(struct connman_network *network);
void __connman_service_update_from_network(struct connman_network *network);
void __connman_service_remove_from_network(struct connman_network *network);

struct connman_service *__connman_service_create_from_provider(
					struct connman_provider *provider);

const char *__connman_service_get_path(struct connman_service *service);
#define	CONNMAN_SERVICE_ORDER_MAX	32767
unsigned int __connman_service_get_order(struct connman_service *service);
connman_bool_t __connman_service_check_portal(struct connman_service *service);

int __connman_service_set_carrier(struct connman_service *service,
						connman_bool_t carrier);
int __connman_service_indicate_state(struct connman_service *service,
					enum connman_service_state state);
int __connman_service_indicate_error(struct connman_service *service,
					enum connman_service_error error);
int __connman_service_indicate_active(struct connman_service *service,
				      connman_bool_t is_active);
connman_bool_t __connman_service_get_connecting_or_connected(
	const struct connman_service *service);
connman_bool_t __connman_service_get_connected(
	const struct connman_service *service);
void __connman_service_restart_connect_timer(struct connman_service *service);

connman_bool_t __connman_service_check_prepared(const struct connman_service *);

struct connman_profile *__connman_service_get_profile(struct connman_service *);
void __connman_service_set_profile(struct connman_service *service,
	struct connman_profile *profile);

enum connman_service_type connman_service_string2type(const char *str);
uint32_t __connman_service_list_to_mask(const char *list);
gchar *__connman_service_mask_to_list(uint32_t mask);
void __connman_service_reset_in_memory(struct connman_service *service);
DBusMessage *__connman_service_set_properties(DBusMessage *msg,
					struct connman_service *service);
DBusMessage *__connman_get_service(DBusMessage *msg);
DBusMessage *__connman_configure_service(DBusMessage *msg);

int __connman_service_connect(struct connman_service *service);
int __connman_service_disconnect(struct connman_service *service);
struct connman_service *__connman_service_lookup(const char *identifier);
int __connman_service_create_and_connect(DBusMessage *msg);
void __connman_service_device_auto_connect(struct connman_device *);
void __connman_service_auto_connect_any(void);
void __connman_service_set_activation_state(struct connman_service *service,
	enum connman_network_activation_state activation_state,
	enum connman_element_error err);
void __connman_service_set_operator(struct connman_service *service,
                                    struct connman_network_operator *op);
void __connman_service_set_olp_url(struct connman_service *service,
				   const char *olp_url,
				   const char *olp_method,
				   const char *olp_postdata);
void __connman_service_set_usage_url(struct connman_service *service,
				     const char *usage_url);

void __connman_service_set_registration_info(
		struct connman_service *service,
		enum connman_network_cellular_technology network_technology,
		enum connman_network_cellular_roaming_state roaming_state);

struct connman_network_apn *__connman_service_get_apn(
		struct connman_service *service);
void __connman_service_save_last_good_apn(struct connman_service *service,
					  const struct connman_network_apn *apn);
enum connman_network_cellular_roaming_state
	__connman_service_get_roaming_state(struct connman_service *service);
void __connman_service_disconnect_if_roaming(struct connman_service *service);

enum connman_service_type __connman_service_string2type(const char *str);
void __connman_service_recheck_portal(void);

#include <connman/provider.h>

#include <connman/notifier.h>

int __connman_notifier_init(void);
void __connman_notifier_cleanup(void);

void __connman_notifier_list_registered(DBusMessageIter *iter, void *);
void __connman_notifier_list_enabled(DBusMessageIter *iter, void *);
void __connman_notifier_list_connected(DBusMessageIter *iter, void *);

void __connman_notifier_register(enum connman_service_type type);
void __connman_notifier_unregister(enum connman_service_type type);
void __connman_notifier_enable(enum connman_service_type type);
void __connman_notifier_disable(enum connman_service_type type);
void __connman_notifier_connect(enum connman_service_type type);
void __connman_notifier_disconnect(enum connman_service_type type);
void __connman_notifier_offlinemode(connman_bool_t enabled);
void __connman_notifier_country_changed(const char *country);
void __connman_notifier_default_changed(struct connman_service *service);
void __connman_notifier_service_state_changed(struct connman_service *service);
void __connman_notifier_system_suspend(void);
void __connman_notifier_system_resume(void);
void __connman_notifier_system_shutdown(void);
void __connman_notifier_profile_push(struct connman_profile *);
void __connman_notifier_profile_pop(struct connman_profile *);

connman_bool_t __connman_notifier_is_enabled(enum connman_service_type type);

#include <connman/rtnl.h>

int __connman_rtnl_init(void);
void __connman_rtnl_start(void);
void __connman_rtnl_cleanup(void);

int __connman_rtnl_send(const void *buf, size_t len);

#include <connman/dns_client.h>

int __connman_dns_client_init(void);
void __connman_dns_client_cleanup(void);
